package com.rabbiter.oes.controller;

import com.rabbiter.oes.entity.ApiResult;
import com.rabbiter.oes.entity.Face;
import com.rabbiter.oes.service.FaceService;
import com.rabbiter.oes.util.ApiResultHandler;
import com.rabbiter.oes.util.FaceRecognition;
import com.rabbiter.oes.util.ImageToBase64Converter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("face")
public class FaceController {

    @Autowired
    private FaceService faceService;

    @GetMapping
    public ApiResult list(){
        return ApiResultHandler.success(faceService.query());
    }

    @PutMapping
    public ApiResult update(@RequestBody Face face) throws IOException {
        Boolean b = faceService.update(face);
        String base64 = ImageToBase64Converter.convertImageToBase64(face.getFaceImg());
        String s = FaceRecognition.updateUser("gorp1", base64, face.getAdminId());
        System.out.println(s);
        if(b){
           return ApiResultHandler.success("修改成功");
       }else {
           return ApiResultHandler.success("修改失败");
       }
    }

}
